#!/usr/bin/env ruby
#
# Created by Jerry Luk on 2008-05-09
# Copyright (c) 2008. All rights reserved.

# Represents the Google Data
module RSS  
  module BaseGDataModelWithGContactExtension
    def append_features(klass)
      super
      base_append_features(klass, GDataModelWithGContactExtension::ELEMENT_NAME_INFOS, GDATA_PREFIX, GDATA_URI)
    end
  end
  
  module GDataModelWithGContactExtension
    extend BaseModel
    extend BaseGDataModelWithGContactExtension
    TEXT_ELEMENTS = [
      # [name, plural_name, content]
      ["phoneNumber",   nil,  true],
      ["email",         nil,  false],
      ["organization",  nil,  true],
      ["postalAddress", "postalAddresses",  true],
      ["im",            nil,  false]
    ]
    
    ATTRIBUTES = GDataModel::ATTRIBUTES + [
      # [name, uri, required, type]
      ["address", "", false, nil]
    ]
    
    ELEMENT_NAME_INFOS = GDataModelWithGContactExtension::TEXT_ELEMENTS.to_a
    ELEMENTS = TEXT_ELEMENTS.map(&:first)
    
    ELEMENT_NAME_INFOS.each do |name, plural_name, content|
      create_class(name, plural_name, GDATA_PREFIX, GDATA_URI, content)
    end    
  end
    
  GDataModelWithGContactExtension::ELEMENTS.each do |name|
    class_name = Utils.to_class_name_with_prefix(name, GDATA_PREFIX)
    BaseListener.install_class_name(GDATA_URI, name, class_name)
  end
  
  GDataModelWithGContactExtension::ELEMENTS.collect! { |name| "#{GDATA_PREFIX}_#{name}"}
end

module RSS
  module Atom
    class Feed
      include GDataModelWithGContactExtension
      class Entry; include GDataModelWithGContactExtension; end
    end

    class Entry
      include GDataModelWithGContactExtension
    end
  end
end
